import axios from "axios";

import { authWhiteList } from "./whiteListApi";

// axios.defaults.baseURL = "http://1.117.229.207:8082";

//请求拦截
axios.interceptors.request.use((config) => {
  // config  当前请求的信息

  // 判断接口是否要登录
  authWhiteList.forEach((item) => {
    if (item === config.url) {
      // config.headers.Authorization   token信息
      const token = sessionStorage.getItem("token")
        ? sessionStorage.getItem("token")
        : "";
      config.headers.Authorization = token;
    }
  });
  return config;
});

//响应后拦截
axios.interceptors.response.use((data) => {
  //console.log(data);

  // data  本次请求成功返回的数据
  return data;
});

export default axios;
